package EightWeek;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
interface GeneralStack
{
	public  Object push(Object item);          
	public  Object pop();              
	public  Object peek();                
	public boolean empty();
	public int size();     
}
class ArrayListGeneralStack implements GeneralStack
{
	private ArrayList list=new ArrayList(); 
	private int size;
	public ArrayListGeneralStack(int size) {
		this.size=size;
	}
	@Override
	public String toString() {
		return list.toString();
	}

	public ArrayList getList() {
		return list;
	}
	public void setList(ArrayList list) {
		this.list = list;
	}
	public int getSize() {
		return size;
	}
	public void setSize(int size) {
		this.size = size;
	}
	@Override
	public Object push(Object item) {
	    if(item==null) return null;
		if(list.size()==size) return null;
		list.add(item);
		return item;
	}
	@Override
	public Object pop() {
		if(!list.isEmpty())
		{
			Object x=list.get(list.size()-1);
			list.remove(x);
			return x;
		}
		return null;
	}
	@Override
	public Object peek() {
		if(!list.isEmpty())
		{
			return list.get(list.size()-1);
		}
		return null;
		
	}
	@Override
	public boolean empty() {
		return list.isEmpty();
	}
	@Override
	public int size() {
		return list.size();
	}
}


class Car 
{
	public Car(int id,String name) {
		this.id=id;
		this.name=name;
	}

	
	private int id;
	private String name;
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	@Override
	public String toString() {
		return "Car [id=" + id + ", name=" + name + "]";
	}
}

public class Fivefive {
	public static void main(String[] args) {
		Scanner input= new Scanner(System.in);
		int m,n;
		double d;
		int i,k,id;
		String name;
		while(input.hasNext())
		{
			String s=input.next();
			if(s.compareTo("quit")==0) break;
			if(s.compareTo("Integer")==0)
			{
				System.out.println("Integer Test");
				int sum=0;
				m=input.nextInt();
				n=input.nextInt();				
				GeneralStack stack=new ArrayListGeneralStack(m);
				
				for(i=0;i<m;i++)
				{
					k=input.nextInt();
					System.out.println("push:"+stack.push(k));
				}
				for(i=0;i<n;i++)
				{
					System.out.println("pop:"+stack.pop());
				}
				System.out.println(stack);
				for(i=n;i<m;i++)
				{
					sum=sum+(Integer)stack.peek();
					stack.pop();
				}
				System.out.println("sum="+sum);
				System.out.println(stack.getClass().getInterfaces()[0]);
			}
			if(s.compareTo("Double")==0)
			{
				System.out.println("Double Test");
				double sum=0;
				m=input.nextInt();
				n=input.nextInt();				
				GeneralStack stack=new ArrayListGeneralStack(m);
				for(i=0;i<m;i++)
				{
					d=input.nextDouble();
					System.out.println("push:"+stack.push(d));
				}
				for(i=0;i<n;i++)
				{
					System.out.println("pop:"+stack.pop());
				}
				System.out.println(stack);
				for(i=n;i<m;i++)
				{
					sum=sum+(Double)stack.peek();
					stack.pop();
				}
				System.out.println("sum="+sum);
				System.out.println(stack.getClass().getInterfaces()[0]);
			}			
			if(s.compareTo("Car")==0)
			{
				System.out.println("Car Test");
				m=input.nextInt();
				n=input.nextInt();
				ArrayListGeneralStack stack=new ArrayListGeneralStack(m);
				for(i=0;i<m;i++)
				{
					id=input.nextInt();
					name=input.next();
					Car car=new Car(id,name);
					System.out.println("push:"+stack.push(car));
				}
				for(i=0;i<n;i++)
				{
					System.out.println("pop:"+stack.pop());
				}
				System.out.println(stack);
				for(i=n;i<m;i++)
				{
					Car p=(Car)stack.peek();
					System.out.println(p.getName());
					stack.pop();
				}
				System.out.println(stack.getClass().getInterfaces()[0]);			
				
			}
			
		}
	
	}

}
